package xyz.thoughtset.viewer.modules.fun.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.ObjectUtils;
import xyz.thoughtset.viewer.common.core.entity.BaseMeta;
import xyz.thoughtset.viewer.common.crud.core.annotation.ApiCRUDPower;

import java.util.List;
import java.util.Map;

@TableName
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiCRUDPower(insert = false, update = false,list = true)
public class FunInfo extends BaseMeta {

    private Integer cacheTime;

    @TableField(exist = false)
    private List<FunParam> params;
    @TableField(exist = false)
    private Map<Integer,List<FunParam>> groupParams;

    public Map<Integer, List<FunParam>> getGroupParams() {
        if (ObjectUtils.isEmpty(params)) {
            return Map.of();
        }
        if (ObjectUtils.isEmpty(groupParams)) {
            this.groupParams = params.parallelStream()
                    .collect(java.util.stream.Collectors.groupingBy(FunParam::getParamType));
        }
        return groupParams;
    }

}
